package reviewAlgorithms.greedyThought;

public class IsSubsequence {
    public static void main(String[] args) {
        String s = "abc";
        String t = "ahbgdc";
        System.out.println(isSubsequence(s,t));
    }

    public static boolean isSubsequence(String s, String t) {
        if (s == null || s.length() < 1){
            return true;
        }
        if (t == null || t.length() < 1) {
            return false;
        }
        if (t.length() < s.length()){
            return false;
        }
        int index = 0;
        for (int i = 0; i < t.length(); i++) {
            if (t.charAt(i) == s.charAt(index)){
                index ++;
                if (index >= s.length()){
                    return true;
                }
            }
        }
        return false;
    }
}
